<div class="boxer">
<div class="box">
		<div class="search search-blacklist">
			<form action="" method="get">
				<i class="ico">搜索条件</i>
				<input type="hidden" name="SizePage" value="{{.SizePage}}"/>
				<input type="text" class="t" placeholder="敏感词名称" name="name" value="{{.name}}" />
				<select name="status" id="black-search-qy">
					{{range $index, $elem := .StatusList}}
					{{if eq $.Status $index}}
					<option value="{{$index}}" selected>{{$elem}}</option>	
					{{else}}
					<option value="{{$index}}">{{$elem}}</option>	
					{{end}}
				{{end}}
				</select>
				<input type="text" class="t" placeholder="创建人" name="creatorname" value="{{.creator}}" />
				<input type="text" class="t time" id="time1" name="createbtime" value="{{.createbtime}}" readonly="readonly" onFocus="var time2=$dp.$('time2');WdatePicker({onpicked:function(){time2.focus();},maxDate:'%y-%M-%d',dateFmt:'yyyy-MM-dd HH:mm'})" placeholder="创建时间" />
				<span class="fg">~</span>
				<input type="text" class="t time" id="time2" name="createetime" value="{{.createetime}}" readonly="readonly" onFocus="var time1=$dp.$('time1');WdatePicker({minDate:'#F{$dp.$D(\'time1\')}',maxDate:'%y-%M-%d',dateFmt:'yyyy-MM-dd HH:mm'})" placeholder="创建时间" />
				<br class="clr" />
				<input type="text" class="t" placeholder="最后修改人" style="margin-left: 435px;" name="modifiername" value="{{.modifier}}" />
				<input type="text" class="t time" id="edittime1" name="modifybtime" value="{{.modifybtime}}" readonly="readonly" onFocus="var edittime2=$dp.$('edittime2');WdatePicker({onpicked:function(){edittime2.focus();},maxDate:'%y-%M-%d',dateFmt:'yyyy-MM-dd HH:mm'})" placeholder="最后修改时间" />
				<span class="fg">~</span>
				<input type="text" class="t time" id="edittime2" name="modifyetime" value="{{.modifyetime}}" readonly="readonly" onFocus="var edittime1=$dp.$('edittime1');WdatePicker({minDate:'#F{$dp.$D(\'edittime1\')}',maxDate:'%y-%M-%d',dateFmt:'yyyy-MM-dd HH:mm'})" placeholder="最后修改时间" />
				<input type="hidden" name="names" value="{{.words}}"/>	
				<input type="submit" class="btn" value="搜 索" />
				<input type="reset" class="btn" value="重 置" />
				<br class="clr" />
			</form>
		</div>
		<div class="default-table-box">
		<div class="quick-operation">
				<button class="red">批量删除</button>
				<button class="orange">批量停用</button>
				<button class="green">批量启用</button>
				<button class="import">导入敏感词</button>
				<br class="clr" />
			</div>
			<div class="default-table margin_ten">
				<table border="0" cellspacing="0" cellpadding="0" width="100%">
					<tr>
						<th width="75"><span>全选</span></th>
						<th>敏感词名称</th>
						<th width="10%">是否启用</th>
						<th width="15%">创建时间</th>
						<th width="10%">创建人</th>
						<th width="15%">最后修改时间</th>
						<th width="10%">最后修改人</th>
						<th width="15%">操作</th>
					</tr>
					 {{range $ind,$elem := .Page.List}}
			          <tr class="row_{{$elem.Id}}">
						<td>
							<span></span>
							<input type="hidden" name="badwords[]" value="{{$elem.Id}}" />
						</td>
			            <td>{{$elem.Name}}</td>
						<td>
						{{if eq $elem.Status 1}}
						是
						{{else}}
						否
						{{end}}
						</td>
						<td>{{date $elem.CreateTime "Y-m-d H:i:s"}}</td>
						<td>{{$elem.CreatorName}}</td>
						<td>
						{{if eq (date $elem.ModifyTime "Y-m-d H:i:s") "0001-01-01 00:00:00"}}
						{{else}}
						{{date $elem.ModifyTime "Y-m-d H:i:s"}}
						{{end}}
						</td>
						<td>{{$elem.ModifierName}}</td>
			            <td>	
						{{if haspermission $.userId "badword:edit"}}
						<a href="javascript:;" class="operation edit" title="编辑" data-id="{{.Id}}"></a>
						{{end}}
						{{if haspermission $.userId "badword:status"}}
						{{if eq $elem.Status 1}}
						<a href="/badword/status/{{.Id}}?status={{.Status}}" class="operation stop" title="停用"></a>
						{{else}}
						<a href="/badword/status/{{.Id}}?status={{.Status}}" class="operation use" title="启用"></a>
						{{end}}
						{{end}}
						{{if haspermission $.userId "badword:delete"}}
							<a href="javascript:;" class="operation del" title="删除" badwordid="{{.Id}}"></a>
			           	{{end}}
						 </td>
			          </tr>
       			   {{end}}
				</table>
			</div>
			<div class="default-pages margin_ten">
				<form method="get" class="pageForm">
					<input type="hidden" name="PageNo" value="{{.Page.PageNo}}" total="{{.Page.TotalPage}}" />
					<input type="hidden" name="SizePage" value="{{.SizePage}}"/>
					
					<input type="hidden" name="name" value="{{.name}}"/>
					<input type="hidden" name="status" value="{{.status}}"/>
					<input type="hidden" name="creatorname" value="{{.creator}}"/>
					
					<input type="hidden" name="createbtime" value="{{.createbtime}}"/>
					
					<input type="hidden" name="createetime" value="{{.createetime}}"/>


					<input type="hidden" name="modifiername" value="{{.modifier}}"/>
					
					<input type="hidden" name="modifybtime" value="{{.modifybtime}}"/>
					<input type="hidden" name="modifybtime" value="{{.modifyetime}}"/>	
					<input type="hidden" name="names" value="{{.words}}"/>	
							
				</form>
				<div>共{{.Page.TotalCount}}条记录，每页&nbsp;<em><b>{{.SizePage}}</b><i>^</i><ul><li data-num="10">10</li><li data-num="20">20</li><li data-num="40">40</li></ul></em>条</div>
				<ul>
					<li><span>{{.Page.PageNo}}/{{.Page.TotalPage}}页</span></li>
					<li><a href="javascript:void(0)" id="first">首页</a></li>
					<li><a href="javascript:void(0)" id="pre">上一页</a></li>
					<li><a href="javascript:void(0)" id="next" total="{{.Page.TotalPage}}">下一页</a></li>
					<li><a href="javascript:void(0)" id="last" pageNo="{{.Page.TotalPage}}">尾页</a></li>
					<li><span>跳转至第</span></li>
					<li><input type="text" id="jump"/></li>
					<li><span>页</span></li>
				</ul>
			</div>
			<div class="quick-operation">
				<button class="red">批量删除</button>
				<button class="orange">批量停用</button>
				<button class="green">批量启用</button><br class="clr" />
			</div>
		</div>
	</div>
	</div>
	<script type="text/javascript">
jQuery(function($){
	$("#jump").on("blur",function(){
		var jump=$(this).val()
		if(jump<=parseInt($("#next").attr("total"))&&jump>=1){
			$("[name=PageNo]").val(jump);
			$(".pageForm").attr("action",window.location).submit()
		}else{
			$(this).val("")
		}
	});

	//首页
	$("#first").on("click",function(){
		$("[name=PageNo]").val(1);
		//$("[name=size]").val({{.size}});
		$(".pageForm").attr("action",window.location).submit()
	});
	//尾页
	$("#last").on("click",function(){
		$("[name=PageNo]").val($(this).attr("pageNo"));
		$(".pageForm").attr("action",window.location).submit()
	});
	//上一页
	$("#pre").on("click",function(){
		if(parseInt($("[name=PageNo]").val())-1>=1){
			$("[name=PageNo]").val(parseInt($("[name=PageNo]").val())-1);
			$(".pageForm").attr("action",window.location).submit()
		}
	});
	//下一页
	$("#next").on("click",function(){
		if(parseInt($("[name=PageNo]").val())+1<=parseInt($("[name=PageNo]").attr("total"))){
			$("[name=PageNo]").val(parseInt($("[name=PageNo]").val())+1);
			$(".pageForm").attr("action",window.location).submit()
		}
	});
	$(".default-pages div em").toggle(function(){
		$(this).find("ul").show();
	},function(){
		$(this).find("ul").hide();
	});

	$(".default-pages div ul li").on("click",function(){
		$(".default-pages div em b").text($(this).data("num"));
		$("[name=PageNo]").val(1);
		$("[name=SizePage]").val($(this).data("num"));
		$(".pageForm").attr("action",window.location).submit();
	});
	
	
	$(".default-table td span").toggle(function(){
		$(this).addClass("selected");
		$(this).parent().children("input[name='select']").attr("value",1);
	},function(){
		$(this).removeClass("selected");
		$(this).parent().children("input[name='select']").attr("value",0);
	});

	$(".default-table th span").toggle(function(){
		$(this).addClass("selected");
		$(".default-table tr").each(function(){
			$(this).find("span").addClass("selected");
			$(this).find("input[name='select']").attr("value",1);
		});
	},function(){
		$(this).removeClass("selected");
		$(".default-table tr").each(function(){
			$(this).find("span").removeClass("selected");
			$(this).find("input[name='select']").attr("value",0);
		});
	});

	var row_default = {
		"input": '',
		"select": ''
	}
	$(".default-table").on("click","a.del",function(){
		var id=$(this).attr("badwordid")
    	layer.confirm('确认删除当前这条敏感词吗？删除后无法恢复！', {
    	  title: '删除',
		  btn: ['是的','取消'], //按钮
		  yes: function(index){
			window.location.href="/badword/delete/"+id
			layer.close(index);
		  }
		});
    }).on("click","a.edit",function(){
    	row_default.input = $(".row_" + $(this).data("id")).find("td:eq(1)").html();
    	row_default.select = $.trim($(".row_" + $(this).data("id")).find("td:eq(2)").html());
    	$(this).parent().html('<a href="javascript:;" onclick="editBadword(this);" class="operation submit" data-id="' + $(this).data("id") + '"></a><a href="javascript:;" class="operation quxiao" data-id="' + $(this).data("id") + '"></a>');
    	$(".row_" + $(this).data("id")).find("td:eq(0) span").addClass("selected");
    	$(".row_" + $(this).data("id")).find("td:eq(0) input[name='select']").attr("value",1);
    	$(".row_" + $(this).data("id")).find("td:eq(1)").html('<input type="text" value="' + $(".row_" + $(this).data("id")).find("td:eq(1)").html() + '" />');
    	var option_html = '';
		if ($.trim($(".row_" + $(this).data("id")).find("td:eq(2)").html()) == "是") {
			option_html += '<option value="1" selected = "selected">是</option><option value="2">否</option>';
		} else{
			option_html += '<option value="1">是</option><option value="2" selected = "selected">否</option>';
		}
    	$(".row_" + $(this).data("id")).find("td:eq(2)").html('<select name="row_13" id="">' + option_html + '</select>');
    }).on("click","a.quxiao",function(){
    	$(this).parent().html('<a href="javascript:;" class="operation edit" data-id="' + $(this).data("id") + '" ></a><a href="javascript:;" class="operation stop"></a><a href="javascript:;" class="operation del"></a>');
    	$(".row_" + $(this).data("id")).find("td:eq(0) span").removeClass("selected");
    	$(".row_" + $(this).data("id")).find("td:eq(0) input[name='select']").attr("value",0);
    	$(".row_" + $(this).data("id")).find("td:eq(1)").html(row_default.input);
    	$(".row_" + $(this).data("id")).find("td:eq(2)").html(row_default.select);
    }).on("click","a.submit",function(){
    	//alert($(this).parent().parent().find("select option:selected").val());
		var name =  $(".row_" + $(this).data("id")).find("td:eq(1)").find("input").val();//输入的name值
    	var status = $(".row_" + $(this).data("id")).find("select option:selected").val();//状态
		$.post("/badword/edit/"+$(this).data("id"),
			{name:name,status:status},
			function(data){
				location.href='/badword/index';
		});
    });

    $(".quick-operation").on("click","button.import",function(){
		location.href="/badword/import";

    }).on("click","button.red",function(){
    	var select_num = 0;
    	$(".default-table tr").each(function(){
			if ($(this).find("span").hasClass("selected")) {
				select_num++;
			}
		});
		if (select_num > 0) {
			layer.confirm('确认删除选中的敏感词吗？删除后无法恢复！', {
	    	  title: '批量删除',
			  btn: ['是的','取消'], //按钮
			  yes: function(index){
				var badwordids = [];
				$(".default-table tr:gt(0)").each(function(){
					if ($(this).find("span").hasClass("selected")) {
						badwordids.push($(this).find("input[name='badwords[]']").val());
					}
				})
				//alert(badwordids);//选中的id集
				$.post("/badword/batch-delete",{ids:badwordids.join(",")},
			  	function(data){
					location.href='/badword/index';
			  	});
			  	layer.close(index);
			  }
			});
		} else {
			layer.alert('请选择需要删除的敏感词！');
		}
    }).on("click","button.orange",function(){
    	var select_num = 0;
    	$(".default-table tr").each(function(){
			if ($(this).find("span").hasClass("selected")) {
				select_num++;
			}
		});
		if (select_num > 0) {
			layer.confirm('确认停用选中的敏感词吗？', {
	    	  title: '批量停用',
			  btn: ['是的','取消'], //按钮
			  yes: function(index){
				var badwordids = [];
				$(".default-table tr:gt(0)").each(function(){
					if ($(this).find("span").hasClass("selected")) {
						badwordids.push($(this).find("input[name='badwords[]']").val());
					}
				})
				//alert(badwordids);//选中的id集
				$.post("/badword/batch-stop",{ids:badwordids.join(",")},
			  	function(data){
					location.href='/badword/index';
			  	});
			  	layer.close(index);
			  }
			});
		} else {
			layer.alert('请选择需要停用的敏感词！');
		}
    }).on("click","button.green",function(){
    	var select_num = 0;
    	$(".default-table tr").each(function(){
			if ($(this).find("span").hasClass("selected")) {
				select_num++;
			}
		});
		if (select_num > 0) {
			layer.confirm('确认启用选中的敏感词吗？', {
	    	  title: '批量启用',
			  btn: ['是的','取消'], //按钮
			  yes: function(index){
				var badwordids = [];
				$(".default-table tr:gt(0)").each(function(){
					if ($(this).find("span").hasClass("selected")) {
						badwordids.push($(this).find("input[name='badwords[]']").val());
					}
				})
				//alert(badwordids);//选中的id集
				$.post("/badword/batch-start",{ids:badwordids.join(",")},
			  	function(data){
					location.href='/badword/index';
			  	});
			  	layer.close(index);
			  }
			});
		} else {
			layer.alert('请选择需要启用的敏感词！');
		}
    });
	
	$(':reset').on('click',function(event){
             $(this).parent('form').find(":input")
             .not(':button, :submit, :reset, :hidden').each(function(){
	             $(this).val('')
             });
            event.preventDefault();
            return false;
        });
		
	nku.droplist.config({'theme':'win7'}).play('black-search-qy');	
});
</script>